package tum0r.util;

import javafx.scene.control.Label;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 工程: ResourcesDatabase<br>
 * 包: tum0r.util<br>
 * 创建者: tum0r<br>
 * 创建时间: 2020/10/4 14:14<br>
 * <br>
 */
public class Log {
    private final String dateFormatString = "yyyy-MM-dd HH:mm:ss";
    private final SimpleDateFormat dateFormat = new SimpleDateFormat(dateFormatString);
    private Label log;

    public Log() {

    }

    public Log(Label log) {
        this.log = log;
    }

    public String getLogMessage(String message) {
        StringBuilder result = new StringBuilder();
        result.append("[");
        result.append(dateFormat.format(new Date()));
        result.append("] ");
        result.append(message == null ? "" : message);
        return result.toString();
    }

    public void displayLog(String message) {
        if (log != null) {
            log.setText(getLogMessage(message));
        }
    }
}
